import { injectable } from 'tsyringe';
import { IRoomRepository } from '../../domain/interfaces/IRoomRepository';

@injectable()
export class RoomRepository implements IRoomRepository {
  private rooms: Record<string, any> = {};

  async create(room: any): Promise<void> {
    this.rooms[room.id] = room;
  }

  async findById(id: string): Promise<any | null> {
    return this.rooms[id] || null;
  }

  async addMember(roomId: string, userId: string): Promise<void> {
    const room = this.rooms[roomId];
    if (!room) return;
    room.memberIds = room.memberIds || [];
    if (!room.memberIds.includes(userId)) room.memberIds.push(userId);
  }

  async removeMember(roomId: string, userId: string): Promise<void> {
    const room = this.rooms[roomId];
    if (!room) return;
    room.memberIds = (room.memberIds || []).filter((id: string) => id !== userId);
  }
}
